New function which calculates position and size for the popup in list
authorMatthias Clasen <maclas@gmx.de>
Sun, 29 Feb 2004 01:33:01 +0000 (01:33 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sun, 29 Feb 2004 01:33:01 +0000 (01:33 +0000)
Sun Feb 29 02:34:35 2004  Matthias Clasen  <maclas@gmx.de>

* gtk/gtkcombobox.c (gtk_combo_box_list_position): New
function which calculates position and size for the popup in
list mode. Currently it only pushes the popup horizontally
into the screen.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkcombobox.c

index 5b28f5304ec6d7c09300b3d0576239eb031acccd..96512c9f72b4f4f1d60e5cb1f139f3f0fd9dce3c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sun Feb 29 02:34:35 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkcombobox.c (gtk_combo_box_list_position): New 
+       function which calculates position and size for the popup in
+       list mode. Currently it only pushes the popup horizontally 
+       into the screen.
+
 Sun Feb 29 01:10:09 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c: Implement the previous fix in a better way,
index 5b28f5304ec6d7c09300b3d0576239eb031acccd..96512c9f72b4f4f1d60e5cb1f139f3f0fd9dce3c 100644 (file)
@@ -1,3 +1,10 @@
+Sun Feb 29 02:34:35 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkcombobox.c (gtk_combo_box_list_position): New 
+       function which calculates position and size for the popup in
+       list mode. Currently it only pushes the popup horizontally 
+       into the screen.
+
 Sun Feb 29 01:10:09 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c: Implement the previous fix in a better way,
index 5b28f5304ec6d7c09300b3d0576239eb031acccd..96512c9f72b4f4f1d60e5cb1f139f3f0fd9dce3c 100644 (file)
@@ -1,3 +1,10 @@
+Sun Feb 29 02:34:35 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkcombobox.c (gtk_combo_box_list_position): New 
+       function which calculates position and size for the popup in
+       list mode. Currently it only pushes the popup horizontally 
+       into the screen.
+
 Sun Feb 29 01:10:09 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c: Implement the previous fix in a better way,
index 5b28f5304ec6d7c09300b3d0576239eb031acccd..96512c9f72b4f4f1d60e5cb1f139f3f0fd9dce3c 100644 (file)
@@ -1,3 +1,10 @@
+Sun Feb 29 02:34:35 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkcombobox.c (gtk_combo_box_list_position): New 
+       function which calculates position and size for the popup in
+       list mode. Currently it only pushes the popup horizontally 
+       into the screen.
+
 Sun Feb 29 01:10:09 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c: Implement the previous fix in a better way,
index 5b28f5304ec6d7c09300b3d0576239eb031acccd..96512c9f72b4f4f1d60e5cb1f139f3f0fd9dce3c 100644 (file)
@@ -1,3 +1,10 @@
+Sun Feb 29 02:34:35 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkcombobox.c (gtk_combo_box_list_position): New 
+       function which calculates position and size for the popup in
+       list mode. Currently it only pushes the popup horizontally 
+       into the screen.
+
 Sun Feb 29 01:10:09 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c: Implement the previous fix in a better way,
index 3651e034c469732a8303884ae0782f073fc4ca1c..fbc7cd3d20fdcdaaab1c8210871c5a930192b3ea 100644 (file)
@@ -234,6 +234,11 @@ static gboolean gtk_combo_box_scroll_event         (GtkWidget        *widget,
                                                     GdkEventScroll   *event);
 
 /* list */
+static void     gtk_combo_box_list_position        (GtkComboBox      *combo_box, 
+                                                   gint             *x, 
+                                                   gint             *y, 
+                                                   gint             *width,
+                                                   gint             *height);
 static void     gtk_combo_box_list_setup           (GtkComboBox      *combo_box);
 static void     gtk_combo_box_list_destroy         (GtkComboBox      *combo_box);
 
@@ -805,6 +810,50 @@ gtk_combo_box_menu_position (GtkMenu  *menu,
   *push_in = TRUE;
 }
 
+static void
+gtk_combo_box_list_position (GtkComboBox *combo_box, 
+                            gint        *x, 
+                            gint        *y, 
+                            gint        *width,
+                            gint        *height)
+{
+  GtkWidget *sample;
+  GdkScreen *screen;
+  gint monitor_num;
+  GdkRectangle monitor;
+  
+  sample = GTK_BIN (combo_box)->child;
+
+  *width = sample->allocation.width;
+  *height = sample->allocation.height;
+
+  gdk_window_get_origin (sample->window, x, y);
+
+  if (combo_box->priv->cell_view_frame)
+    {
+       *x -= GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
+            GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
+       *width += 2 * (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
+            GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
+    }
+
+  if (GTK_WIDGET_NO_WINDOW (sample))
+    {
+      *x += sample->allocation.x;
+      *y += sample->allocation.y;
+    }
+  
+  screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
+  monitor_num = gdk_screen_get_monitor_at_window (screen, 
+                                                 GTK_WIDGET (combo_box)->window);
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+  
+  if (*x < monitor.x)
+    *x = monitor.x;
+  else if (*x + *width > monitor.x + monitor.width)
+    *x = monitor.x + monitor.width - *width;
+} 
+
 /**
  * gtk_combo_box_popup:
  * @combo_box: a #GtkComboBox
@@ -820,7 +869,6 @@ void
 gtk_combo_box_popup (GtkComboBox *combo_box)
 {
   gint x, y, width, height;
-  GtkWidget *sample;
 
   g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
 
@@ -846,33 +894,10 @@ gtk_combo_box_popup (GtkComboBox *combo_box)
       return;
     }
 
-  /* size it */
-  sample = GTK_BIN (combo_box)->child;
-
-  width = sample->allocation.width;
-  height = sample->allocation.height;
-
-  gdk_window_get_origin (sample->window,
-                         &x, &y);
-
-  if (combo_box->priv->cell_view_frame)
-    {
-       x -= GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
-            GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
-       width += 2 * (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
-            GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
-    }
-
-  gtk_widget_set_size_request (combo_box->priv->popup_window, width, -1);
-  
-  if (GTK_WIDGET_NO_WINDOW (sample))
-    {
-      x += sample->allocation.x;
-      y += sample->allocation.y;
-    }
+  gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
 
-  gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window),
-                   x, y + height);
+  gtk_widget_set_size_request (combo_box->priv->popup_window, width, -1);  
+  gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y + height);
 
   /* popup */
   gtk_widget_show_all (combo_box->priv->popup_window);